var k1=new Array();
var y=0;
var yi=1;
Highcharts.setOptions({
    global: {
        useUTC: false
    }
});
function activeLastPointToolip(chart) {
    var points = chart.series[0].points;
    chart.tooltip.refresh(points[points.length -1]);
}
$.ajax({
    url:url_trading_this_time,
    type:'get',
    success:function(data){
        data = JSON.parse(data);
        y=parseInt(data.money);
        // x=(new Date()).getTime();
        x=data.time;
        // k1[0]=[0,0];
        k1[0]=[x,y];
        $('#containera3').highcharts({
            chart: {
                type: 'spline',
                animation: Highcharts.svg, // don't animate in old IE
                marginRight: 10,
                backgroundColor:'transparent',
                events: {
                    load: function () {
                        var series = this.series[0],
                            chart = this;
                        setInterval(function () {
                            $.ajax({
                                url:url_trading_this_time,
                                type:'get',
                                success:function(data){
                                    data = JSON.parse(data)
                                    y=parseInt(data.money);
                                    // x=(new Date()).getTime()
                                    x=data.time;
                                    if(yi<7){
                                        series.addPoint([x, y], true, false);
                                        activeLastPointToolip(chart);
                                        yi++;
                                    }else{
                                        series.addPoint([x, y], true, true);
                                        activeLastPointToolip(chart);
                                    }
                                }
                            });
                        }, 2000);
                    }
                },
            },
            credits: {
                enabled: false //不显示LOGO
            },
            title: {
                text: '炫生活服务平台今日交易数据',
                style: {
                    color: '#666693',
                    fontWeight: 'bolder',
                    fontSize: '18px'
                }

            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 150,
                labels: {  //设置x或者y轴字体样式
                    style: {
                        color: '#aaa',
                        fontFamily:'微软雅黑'
                    }
                }
            },
            yAxis: {
                title: {
                    text: '交易金额',
                    style: {
                        color: '#aaa',
                        fontSize: '12px'
                    }
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    tickInterval:1000,
                    color: '#808080'
                }],
                labels: {
                    formatter: function () {
                        return this.value
                    },
                    style: {
                        color: '#aaa',
                        fontFamily:'微软雅黑'
                    }
                }
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.series.name + '</b><br/>' +Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +Highcharts.numberFormat(this.y, 2)+'元';
                }
            },
            legend: {
                enabled: false
            },
            exporting: {
                enabled: false
            },
            series: [{
                name: '当前金额',
                data: k1
            }]
        }, function(c) {
            activeLastPointToolip(c);
        });
    }
});